<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    #parent{
        width: 500px;height: 500px;
        border: 1px solid salmon;
    }
    #child{
        width: 300px; height: 300px;
        border: 1px solid skyblue;
        margin: 20px;
    }
    </style>
</head>
<body>
    <div id="parent">
        parent
        <div id="child">child</div>
    </div>
    <script>
        // 当子元素触发一个事件的时候，倘若父元素也有相同的事件，父元素的事件也会触发
        var parent =document.getElementById("parent");
        var child = document.getElementById("child");
        parent.onclick = function(){
            alert("parent");
        }
        child.onclick =function(event){
            alert("child");
            // 阻止事件冒泡
            event.stopPropagation();
        }
    </script>
</body>
</html>